package mt.dummy;

import static org.junit.Assert.*;

import java.io.ObjectOutputStream;

import mt.Order;
import mt.comm.ServerMessage;
import mt.comm.ServerSideMessage.Type;

import org.junit.Test;

public class ServerCommDummyTest {
	
	ServerCommDummy server = new ServerCommDummy();

	@Test
	public void testStart() {
		server.start();
	}

	@Test
	public void testHasNextMessage() {
        assertFalse(server.hasNextMessage());
        ServerMessage msg = new ServerMessage(Type.CONNECTED, "name", null) ;
	}

	@Test
	public void testGetNextMessage() {
		assertNull(server.getNextMessage());
	}

	@Test
	public void testSendError() {
	}

	@Test
	public void testClientIsConnected() {
		assertFalse(server.clientIsConnected("vasco"));
		ObjectOutputStream out = null;	
		ServerMessage smsg= new ServerMessage(Type.CONNECTED, "vasco", null);
		server.addNewClient("vasco", out, smsg);
		assertTrue(server.clientIsConnected("vasco"));
	}

	@Test
	public void testDisconnectClient() {
		assertFalse(server.clientIsConnected("vasco"));
		ObjectOutputStream out = null;	
		ServerMessage smsg= new ServerMessage(Type.CONNECTED, "vasco", null);
		server.addNewClient("vasco", out, smsg);
		assertTrue(server.clientIsConnected("vasco"));
		server.disconnectClient("vasco");
		assertFalse(server.clientIsConnected("vasco"));
	}

	@Test
	public void testSendOrder() {
		server.sendOrder("Vasco", Order.createBuyOrder("Vasco", "BES", 10, 10));
	}

	@Test
	public void testAddNewClient() {
		assertFalse(server.clientIsConnected("vasco"));
		ObjectOutputStream out = null;	
		ServerMessage smsg= new ServerMessage(Type.CONNECTED, "vasco", null);
		server.addNewClient("vasco", out, smsg);
		assertTrue(server.clientIsConnected("vasco"));
	}

	@Test
	public void testAddNewMessage() {
		ServerMessage smsg= new ServerMessage(Type.CONNECTED, "vasco", null);
		server.addNewMessage(smsg);
		assertNotNull(server.getMessages());
	}

	@Test
	public void testGetMessages() {
		assertNotNull(server.getMessages());
		server.getMessages();
	}

	@Test
	public void testGetOut() {
		ObjectOutputStream out=server.getOut();
	}

	@Test
	public void testUserAlreadyExists() {
		server.userAlreadyExists();
	}

}
